#include <stdio.h>
#include <tchar.h>

//#define BITSRC_FROM0
//#define BITDST_FROM0

#include <crbitio.h>

enum { LEN = 60 };
//char vec[] = "000000000000000000000000000000000000000000000000000000000000000000000000";
//char vec[] = "11111111111111111111111111111111111111111111111111111111111111111111111";
char vec[] = "111011100100110101000110100000010100011101110111000010000000001101000000";

int _tmain(int argc, _TCHAR* argv[])
{
	printf("0-------");
	printf("1-------");
	printf("2-------");
	printf("3-------");
	printf("4-------");
	printf("5-------");
	printf("6-------");
	printf("7-------");
	printf("\n");

	printf("bool: ");
	printf(vec);
	printf("\n");

	bool val[LEN];
	for (int i=0; i<LEN; ++i)
		val[i] = !!(vec[i]-'0');

	char org[LEN];
	char str[LEN];
	char buf[LEN];
	char cpy[LEN];
	int len = 30;

	printf("base: ");
	bitfill(val, org, LEN);
	sbprintf<LEN>(str, org, LEN);
	printf(str);
	printf("\n");

	printf("fill: ");
	bitfill(val, buf, len, 3);
	sbprintf<LEN>(str, buf, len, 3);
	printf(str);
	printf("\n");

	printf("copy: ");
	bitcopy(cpy, buf, len, 5, 3);
	sbprintf<LEN>(str, cpy, len, 5);
	printf(str);
	printf("\n");

	printf("find: ");
	int ret = bitfind(cpy, len, 11, 5);
	ASSERT(ret >= 0);
	for (int i=0; i<LEN; ++i)
		if (str[i] == '0')
			str[i] = ' ';
	str[ret] = '^';
	str[ret+1] = NULL;
	printf(str);
	printf("\n");

	system("pause");
	return 0;
}
